// 腾讯云 COS 上传文件

import COS from "cos-nodejs-sdk-v5";

// 初始化 COS 客户端    
const cos = new COS({
    SecretId: process.env.COS_SECRET_ID,
    SecretKey: process.env.COS_SECRET_KEY,
});

// 上传文件
export async function uploadFile(file: string, key: string) {
    const result = await cos.putObject({
        Bucket: process.env.COS_BUCKET,
        Region: process.env.COS_REGION,
        Key: key,
        Body: file,
    });
    return result;
}

// 删除文件
export async function deleteFile(key: string) {
    const result = await cos.deleteObject({
        Bucket: process.env.COS_BUCKET,
        Region: process.env.COS_REGION,
        Key: key,
    });
    return result;
}

// 获取文件
export async function downloadFile(key: string) {
    const result = await cos.getObject({
        Bucket: process.env.COS_BUCKET,
        Region: process.env.COS_REGION,
        Key: key,
    });
    return result;
}